<template>
  <div>
    <!-- 新增编辑的弹层 -->
    <el-dialog :visible="showDialog" title="弹层标题" @close="closefn">
      <!-- 表单内容 -->
      <el-form ref="addform" :inline="true" label-width="100px" :model="formData">
        <el-form-item label="菜单名称">
          <el-input v-model="formData.title" style="width:300px" />
        </el-form-item>
        <el-form-item label="菜单地址">
          <el-input v-model="formData.path" style="width:300px" />
        </el-form-item>
        <el-form-item label="组件地址">
          <el-input v-model="formData.component" style="width:300px" />
        </el-form-item>
        <el-form-item label="权限标识">
          <el-input v-model="formData.mark" style="width:300px" />
        </el-form-item>
        <el-form-item label="菜单图标">
          <el-input v-model="formData.icon" style="width:300px" />
        </el-form-item>
        <el-form-item label="重定向">
          <el-input v-model="formData.redirect" style="width:300px" />
        </el-form-item>
        <el-form-item label="是否外链" prop="resource" style="width:399px">

          <el-radio v-model="formData.is_link" :label="1">是</el-radio>
          <el-radio v-model="formData.is_link" :label="0">否</el-radio>

        </el-form-item>
        <el-form-item label="排序" style="width:300px">
          <el-input-number v-model="formData.sort" :min="1" :max="10" label="描述" @change="handleChange" />
        </el-form-item>
        <el-form-item label="是否显示" style="width:399px">

          <el-radio v-model="formData.is_show" :label="1">是</el-radio>
          <el-radio v-model="formData.is_show" :label="0">否</el-radio>

        </el-form-item>
        <el-form-item label="是否缓存" style="width:300px">

          <el-radio v-model="formData.is_cache" :label="1">是</el-radio>
          <el-radio v-model="formData.is_cache" :label="0">否</el-radio>

        </el-form-item>
      </el-form>
      <template #footer>
        <div style="text-align: right;">
          <el-button @click="closefn">取消</el-button>
          <el-button type="primary" @click="addfn">确定</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script>
import { addfnAPI, ADDUpdataAPI } from '@/api/system'
export default {
  props: {
    showDialog: {
      type: Boolean,
      redirect: true
    }
  },
  data() {
    return {
      formData: {
        title: '',
        path: '',
        component: '',
        mark: '',
        icon: '',
        redirect: '',
        is_link: 1,
        sort: '',
        is_show: 1,
        is_cache: 1,
        pid: '',
        type: ''
      }
    }
  },
  methods: {
    closefn() {
      this.$emit('update:showDialog', false)
      this.$refs.addform.resetFields()
      this.formData = {
        title: '',
        path: '',
        component: '',
        mark: '',
        icon: '',
        redirect: '',
        is_link: '1',
        sort: '',
        is_show: '1',
        is_cache: '1',
        pid: '',
        type: ''
      }
    },
    handleChange(value) {
      // console.log(value)
    },
    addfn() {
      this.$refs.addform.validate(async(flag) => {
        if (flag) {
          if (this.formData.id) {
            await ADDUpdataAPI(this.formData)
            this.$message.success('修改成功')
          } else {
            await addfnAPI(this.formData)
            this.$message.success('添加成功')
          }
          this.closefn()
          this.$parent.Userlist()
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
 ::v-deep.el-input__inner{
   width: 200px;
 }
</style>
